package com.beiing.leafchat.renderer;


import com.beiing.leafchat.bean.Axis;
import com.beiing.leafchat.bean.SlidingLine;
import com.beiing.leafchat.support.LeafUtil;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.render.Path;
import ohos.agp.render.PathEffect;
import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * Created by chenliu on 2017/1/9.<br/>
 * 描述：
 * </br>
 */

public class SlideSelectLineRenderer extends LeafLineRenderer {
    /**移动标尺线**/
    private Paint slidePaint;

    public SlideSelectLineRenderer(Context context, Component view) {
        super(context, view);
    }

    @Override
    protected void initPaint() {
        super.initPaint();
        slidePaint = new Paint();
        slidePaint.setAntiAlias(true);
    }

    /**
     * 竖直滑动标尺线
     * @param canvas 绘制信息
     * @param axisX X轴
     * @param slidingLine 滑动线
     * @param moveX X方向移动距离
     * @param moveY Y方向移动距离
     */
    public void drawSlideLine(Canvas canvas, Axis axisX, SlidingLine slidingLine, float moveX, float moveY) {
        slidePaint.setStrokeWidth(LeafUtil.dp2px(mContext, 1));
        slidePaint.setColor(new Color(slidingLine.getSlideLineColor()));
        if(slidingLine.isDash()){
            float dash = LeafUtil.dp2px(mContext, 2);
            slidePaint.setPathEffect(new PathEffect(new float[]{dash, dash, dash, dash}, 0));
        }
        Path path = new Path();
        path.moveTo(moveX, moveY);
        path.lineTo(moveX, axisX.getStartY());
        canvas.drawPath(path, slidePaint);

        slidePaint.setPathEffect(null);
        slidePaint.setStyle(Paint.Style.FILL_STYLE);
        slidePaint.setColor(Color.WHITE);
        float slidePointRadius = slidingLine.getSlidePointRadius();
        canvas.drawCircle(moveX, moveY, LeafUtil.dp2px(mContext, slidePointRadius) , slidePaint);
        slidePaint.setStyle(Paint.Style.STROKE_STYLE);
        slidePaint.setStrokeWidth(LeafUtil.dp2px(mContext, 1));
        slidePaint.setColor(new Color(slidingLine.getSlidePointColor()));
        canvas.drawCircle(moveX, moveY, LeafUtil.dp2px(mContext, slidePointRadius) , slidePaint);
        if(slidingLine.getSlidePointColor() != 0){
            slidePaint.setAlpha(100);
            canvas.drawCircle(moveX, moveY, LeafUtil.dp2px(mContext, LeafUtil.add(slidePointRadius, + 2)) , slidePaint);
        }
    }

}
